
#include "i2c_select.h"
#include "apm32f0xx_gpio.h"
#include "bsp_gpio.h"



void Select_AB(uint8_t aa,uint8_t bb)
{
    if(aa)
        GPIO_SetBit(SELECT_A1_PORT, SELECT_A1_PIN );
    else
        GPIO_ClearBit(SELECT_A1_PORT, SELECT_A1_PIN );

    if(bb)
        GPIO_SetBit(SELECT_B1_PORT, SELECT_B1_PIN );
    else
        GPIO_ClearBit(SELECT_B1_PORT, SELECT_B1_PIN );
}

void Select_AB2(uint8_t aa,uint8_t bb)
{
    if(aa)
        GPIO_SetBit(SELECT_A2_PORT, SELECT_A2_PIN );
    else
        GPIO_ClearBit(SELECT_A2_PORT, SELECT_A2_PIN );

    if(bb)
        GPIO_SetBit(SELECT_B2_PORT, SELECT_B2_PIN );
    else
        GPIO_ClearBit(SELECT_B2_PORT, SELECT_B2_PIN );
}


void I2C_Channel_Select(I2CCHType ch)
{
    switch (ch)
    {
    case I2CCH_1:
    {
        USER.g_IIC = 0;
        Select_AB(0, 0);
        Select_AB2(0, 0);
    }
    break;

    case I2CCH_2:
    {
        USER.g_IIC = 0;
        Select_AB(0,0);
        Select_AB2(1,0);
    }
    break;

    case I2CCH_3:
    {
        USER.g_IIC = 0;
        Select_AB(0,0);
        Select_AB2(0,1);
    }
    break;

    case I2CCH_4:
    {
        USER.g_IIC = 0;
        Select_AB(0,0);
        Select_AB2(1,1);
    }
    break;

    case I2CCH_5:
    {
        USER.g_IIC = 1;
        Select_AB(0,0);
        Select_AB2(0,0);
    }
    break;

    case I2CCH_6:
    {
        USER.g_IIC = 1;
        Select_AB(1,0);
        Select_AB2(0,0);
    }
    break;

    case I2CCH_7:
    {
        USER.g_IIC = 1;
        Select_AB(0,1);
        Select_AB2(0,0);
    }
    break;

    case I2CCH_8:
    {
        USER.g_IIC = 1;
        Select_AB(1,1);
        Select_AB2(0,0);
    }
    break;

    default:
        break;
    }

}
















